5 * @subpackage SpecialPage
11 require_once( "LinksUpdate.php" );
16 function wfSpecialMovepage() {
17 global $wgUser, $wgOut, $wgRequest, $action, $wgOnlySysopMayMove;
19 # check rights. We don't want newbies to move pages to prevents possible attack
20 if ( $wgUser->isAnon() or $wgUser->isBlocked() or ($wgOnlySysopMayMove and $wgUser->isNewbie())) {
21 $wgOut->errorpage( "movenologin", "movenologintext" );
24 # We don't move protected pages
26 $wgOut->readOnlyPage();
30 $f = new MovePageForm();
32 if ( 'success' == $action ) {
34 } else if ( 'submit' == $action && $wgRequest->wasPosted()
35 && $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) ) ) {
45 * @subpackage SpecialPage
48 var $oldTitle, $newTitle, $reason; # Text input
49 var $moveTalk, $deleteAndMove;
51 function MovePageForm() {
53 $this->oldTitle
= $wgRequest->getText( 'wpOldTitle', $wgRequest->getVal( 'target' ) );
54 $this->newTitle
= $wgRequest->getText( 'wpNewTitle' );
55 $this->reason
= $wgRequest->getText( 'wpReason' );
56 $this->moveTalk
= $wgRequest->getBool( 'wpMovetalk', true );
57 $this->deleteAndMove
= $wgRequest->getBool( 'wpDeleteAndMove' );
60 function showForm( $err ) {
61 global $wgOut, $wgUser, $wgLang;
63 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
65 if ( $this->oldTitle
== '' ) {
66 $wgOut->errorpage( 'notargettitle', 'notargettext' );
70 $ot = Title
::newFromURL( $this->oldTitle
);
71 $oldTitle = $ot->getPrefixedText();
73 $encOldTitle = htmlspecialchars( $this->oldTitle
);
74 if( $this->newTitle
== '' ) {
75 # Show the current title as a default
76 # when the form is first opened.
77 $encNewTitle = $oldTitle;
79 $nt = Title
::newFromURL( $this->newTitle
);
81 // Check if it's valid
82 if ( !$nt->isValidMoveTarget( $ot ) ) {
83 $err = 'articleexists';
85 $encNewTitle = htmlspecialchars( $this->newTitle
);
87 $encNewTitle = $oldTitle;
90 $encReason = htmlspecialchars( $this->reason
);
92 if ( $err == 'articleexists' && $wgUser->isAllowed( 'delete' ) ) {
93 $wgOut->addWikiText( wfMsg( 'delete_and_move_text', $encNewTitle ) );
94 $movepagebtn = wfMsg( 'delete_and_move' );
95 $submitVar = 'wpDeleteAndMove';
98 $wgOut->addWikiText( wfMsg( 'movepagetext' ) );
99 $movepagebtn = wfMsg( 'movepagebtn' );
100 $submitVar = 'wpMove';
103 if ( !$ot->isTalkPage() ) {
104 $wgOut->addWikiText( wfMsg( 'movepagetalktext' ) );
107 $movearticle = wfMsg( 'movearticle' );
108 $newtitle = wfMsg( 'newtitle' );
109 $movetalk = wfMsg( 'movetalk' );
110 $movereason = wfMsg( 'movereason' );
112 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Movepage' );
113 $action = $titleObj->escapeLocalURL( 'action=submit' );
114 $token = htmlspecialchars( $wgUser->editToken() );
117 $wgOut->setSubtitle( wfMsg( 'formerror' ) );
118 $wgOut->addHTML( '<p class="error">' . wfMsg($err) . "</p>\n" );
121 if ( $this->moveTalk
) {
122 $moveTalkChecked = " checked='checked'";
124 $moveTalkChecked = '';
128 <form id=\"movepage\" method=\"post\" action=\"{$action}\">
131 <td align='right'>{$movearticle}:</td>
132 <td align='left'><strong>{$oldTitle}</strong></td>
135 <td align='right'>{$newtitle}:</td>
137 <input type='text' size='40' name=\"wpNewTitle\" value=\"{$encNewTitle}\" />
138 <input type='hidden' name=\"wpOldTitle\" value=\"{$encOldTitle}\" />
142 <td align='right'>{$movereason}:</td>
144 <input type='text' size=40 name=\"wpReason\" value=\"{$encReason}\" />
148 if ( ! $ot->isTalkPage() ) {
152 <input type='checkbox' name=\"wpMovetalk\"{$moveTalkChecked} value=\"1\" />
161 <input type='submit' name=\"{$submitVar}\" value=\"{$movepagebtn}\" />
165 <input type='hidden' name='wpEditToken' value=\"{$token}\" />
170 function doSubmit() {
171 global $wgOut, $wgUser, $wgLang;
172 global $wgDeferredUpdateList, $wgMessageCache;
173 global $wgUseSquid, $wgRequest;
174 $fname = "MovePageForm::doSubmit";
176 # Variables beginning with 'o' for old article 'n' for new article
178 $ot = Title
::newFromText( $this->oldTitle
);
179 $nt = Title
::newFromText( $this->newTitle
);
181 # Delete to make way if requested
182 if ( $wgUser->isAllowed( 'delete' ) && $this->deleteAndMove
) {
183 $article = new Article( $nt );
184 // This may output an error message and exit
185 $article->doDelete( wfMsgForContent( 'delete_and_move_reason' ) );
188 # don't allow moving to pages with # in
189 if ( !$nt ||
$nt->getFragment() != '' ) {
190 $this->showForm( 'badtitletext' );
194 $error = $ot->moveTo( $nt, true, $this->reason
);
195 if ( $error !== true ) {
196 $this->showForm( $error );
200 # Update counters if the article got moved into or out of NS_MAIN namespace
201 $ons = $ot->getNamespace();
202 $nns = $nt->getNamespace();
204 # moved out of article namespace?
205 if ( $ons == NS_MAIN
and $nns != NS_MAIN
) {
206 $u = new SiteStatsUpdate( 0, 1, -1); # not viewed, edited, removing
208 # moved into article namespace?
209 elseif ( $ons != NS_MAIN
and $nns == NS_MAIN
) {
210 $u = new SiteStatsUpdate( 0, 1, +
1 ); # not viewed, edited, adding
214 if ( $u !== false ) {
215 # save it for later update
216 array_push( $wgDeferredUpdateList, $u );
221 # (1) the checkbox says to,
222 # (2) the namespaces are not themselves talk namespaces, and of course
224 if ( ( $wgRequest->getVal('wpMovetalk') == 1 ) &&
225 ( ! Namespace::isTalk( $ons ) ) &&
226 ( ! Namespace::isTalk( $nns ) ) ) {
228 # get old talk page namespace
229 $ons = Namespace::getTalk( $ons );
230 # get new talk page namespace
231 $nns = Namespace::getTalk( $nns );
233 # make talk page title objects
234 $ott = Title
::makeTitle( $ons, $ot->getDBkey() );
235 $ntt = Title
::makeTitle( $nns, $nt->getDBkey() );
238 $error = $ott->moveTo( $ntt, true, $this->reason
);
239 if ( $error === true ) {
246 # Give back result to user.
247 $titleObj = Title
::makeTitle( NS_SPECIAL
, 'Movepage' );
248 $success = $titleObj->getFullURL(
249 'action=success&oldtitle=' . wfUrlencode( $ot->getPrefixedText() ) .
250 '&newtitle=' . wfUrlencode( $nt->getPrefixedText() ) .
251 '&talkmoved='.$talkmoved );
253 $wgOut->redirect( $success );
256 function showSuccess() {
257 global $wgOut, $wgRequest, $wgRawHtml;
259 $wgOut->setPagetitle( wfMsg( 'movepage' ) );
260 $wgOut->setSubtitle( wfMsg( 'pagemovedsub' ) );
261 $oldtitle = $wgRequest->getVal('oldtitle');
262 $newtitle = $wgRequest->getVal('newtitle');
263 $talkmoved = $wgRequest->getVal('talkmoved');
265 $text = wfMsg( 'pagemovedtext', $oldtitle, $newtitle );
267 # Temporarily disable raw html wikitext option out of XSS paranoia
268 $marchingantofdoom = $wgRawHtml;
270 $wgOut->addWikiText( $text );
271 $wgRawHtml = $marchingantofdoom;
273 if ( $talkmoved == 1 ) {
274 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagemoved' ) . "</p>\n" );
275 } elseif( 'articleexists' == $talkmoved ) {
276 $wgOut->addHTML( "\n<p><strong>" . wfMsg( 'talkexists' ) . "</strong></p>\n" );
278 $ot = Title
::newFromURL( $oldtitle );
279 if ( ! $ot->isTalkPage() ) {
280 $wgOut->addHTML( "\n<p>" . wfMsg( 'talkpagenotmoved', wfMsg( $talkmoved ) ) . "</p>\n" );